package com.yueqian.system.controller;


import java.util.List;

import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yueqian.framework.entity.ResultEntity;
import com.yueqian.system.converter.RoleConvert;
import com.yueqian.system.entity.Role;
import com.yueqian.system.service.RoleService;
import com.yueqian.system.vo.req.RoleReqVO;
import com.yueqian.system.vo.res.RoleResVO;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role")
public class RoleController {

	@Resource
	private RoleService roleService;


	@GetMapping("/selectPageData")
	public ResultEntity<IPage<RoleResVO>> selectPageData(RoleReqVO reqVO) {
		return ResultEntity.success(roleService.selectPageData(reqVO));
	}


	@GetMapping("/selectListData")
	public ResultEntity<List<RoleResVO>> selectListData(RoleReqVO reqVO) {
		List<Role> roleList = roleService.selectListData(reqVO);
		List<RoleResVO> roleResVOS = RoleConvert.INSTANCE.toResList(roleList);
		return ResultEntity.success(roleResVOS);
	}

	@GetMapping("/getDetail")
	public ResultEntity<RoleResVO> getDetail(@RequestParam(value = "id", required = false) Long id) {
		RoleResVO roleResVO = roleService.getDetail(id);
		return ResultEntity.success(roleResVO);
	}

	@PostMapping("/add")
	public ResultEntity<Long> add(@RequestBody RoleReqVO reqVO) {
		return ResultEntity.success(roleService.add(reqVO));
	}


	@GetMapping("/delete")
	public ResultEntity<Long> delete(@RequestParam(value = "id") Long id) {
		return ResultEntity.success(roleService.delete(id));
	}


	@PostMapping("/editStatus")
	public ResultEntity<Boolean> editStatus(@RequestBody RoleReqVO roleReqVO) {
		roleService.editStatus(roleReqVO);
		return ResultEntity.ok(true);
	}

	@GetMapping("/getRoleType")
	public ResultEntity<List<RoleResVO>> getRoleType() {
		return ResultEntity.success(roleService.getRoleType());
	}

}
